<template>
   <div class="container" v-show="isShow" :style="styleObj">
      <router-link to="/">
        <span class="iconfont detail-back">&#xe624;</span>
      </router-link>
     景点详情
    </div>
</template>

<script>
export default {
  name: 'Header',
  data () {
    return {
      isShow: true,
      styleObj: {
        opacity: 0
      }
    }
  },
  methods: {
    handlerScroll () {
      // 60的时候将标题显示出来
      const top = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset
      console.log(top)
      if (top < 60) {
        this.styleObj.opacity = top / 60
      } else if (top > 60) {
        this.styleObj.opacity = 1
      }
    }
  },
  mounted () {
    window.addEventListener('scroll', this.handlerScroll)
  },
  unmounted () {
    window.removeEventListener('scroll', this.handlerScroll)
  }
}
</script>

<style lang="stylus" scoped>
  @import "~styles/varibles.styl"
  .container
    position fixed
    z-index 2
    top 0
    width 100%
    font-size .3rem
    height $headerHeight
    background $headerColor
    line-height $headerLineHeight
    color #fff
    text-align center
    .detail-back
      position absolute
      left .2rem
      font-size .3rem
      color #fff
</style>
